package web.suzy.oj.controller.oj;

import org.apache.shiro.authz.annotation.RequiresAuthentication;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import web.suzy.oj.annotation.AnonApi;
import web.suzy.oj.common.exception.StatusFailException;
import web.suzy.oj.common.exception.StatusSystemErrorException;
import web.suzy.oj.common.result.ResultBean;
import web.suzy.oj.pojo.dto.ChangeEmailDTO;
import web.suzy.oj.pojo.dto.ChangePasswordDTO;
import web.suzy.oj.pojo.dto.CheckUsernameOrEmailDTO;
import web.suzy.oj.pojo.vo.*;
import web.suzy.oj.service.oj.AccountService;

/**
 * YangSuzy 软件工作室
 * 类名: AccountController
 * 描述: 账户控制器
 * 功能: 负责处理账号的相关操作
 *
 * @author YangSuzy
 * Date: 2022/11/14 18:04
 */
@RestController
@RequestMapping("/api")
public class AccountController {
    @Autowired
    private AccountService accountService;

    /**
     * 方法名: checkUsernameOrEmail
     * 描述: 检查用户名或邮箱是否存在
     *
     * @param checkUsernameOrEmailDto
     * @return web.suzy.oj.common.result.ResultBean<web.suzy.oj.pojo.vo.CheckUsernameOrEmailVO>
     * @date 2022/11/14 18:05
     * @auther YangSuzy
     **/
    @RequestMapping(value = "/check-username-or-email", method = RequestMethod.POST)
    @AnonApi
    public ResultBean<CheckUsernameOrEmailVO> checkUsernameOrEmail(@RequestBody CheckUsernameOrEmailDTO checkUsernameOrEmailDto) {
        return accountService.checkUsernameOrEmail(checkUsernameOrEmailDto);
    }

    /**
     * 方法名: changePassword
     * 描述: 修改密码
     *
     * @param changePasswordDto
     * @return web.suzy.oj.common.result.ResultBean<web.suzy.oj.pojo.vo.ChangeAccountVO>
     * @date 2022/11/14 20:27
     * @auther YangSuzy
     **/
    @PostMapping("/change-password")
    @RequiresAuthentication
    public ResultBean<ChangeAccountVO> changePassword(@RequestBody ChangePasswordDTO changePasswordDto) {
        return accountService.changePassword(changePasswordDto);
    }

    /**
     * 方法名: changeEmail
     * 描述: 修改邮箱
     *
     * @param changeEmailDto
     * @return web.suzy.oj.common.result.ResultBean<web.suzy.oj.pojo.vo.ChangeAccountVO>
     * @date 2022/11/15 11:55
     * @auther YangSuzy
     **/
    @PostMapping("/change-email")
    @RequiresAuthentication
    public ResultBean<ChangeAccountVO> changeEmail(@RequestBody ChangeEmailDTO changeEmailDto) {
        return accountService.changeEmail(changeEmailDto);
    }


    /**
     * 方法名: changeUserInfo
     * 描述: 修改用户信息
     *
     * @param userInfoVo
     * @return web.suzy.oj.common.result.ResultBean<web.suzy.oj.pojo.vo.UserInfoVO>
     * @date 2022/11/15 12:13
     * @auther YangSuzy
     **/
    @PostMapping("/change-userInfo")
    @RequiresAuthentication
    public ResultBean<UserInfoVO> changeUserInfo(@RequestBody UserInfoVO userInfoVo) {
        return accountService.changeUserInfo(userInfoVo);
    }


    /**
     * 方法名: getUserHomeInfo
     * 描述: 处理用户主页的数据请求，返回解决题目数，AC的题目列表，提交总数，AC总数等用户信息
     *
     * @param uid      用户ID
     * @param username 用户名
     * @return web.suzy.oj.common.result.ResultBean<web.suzy.oj.pojo.vo.UserHomeVO>
     * @date 2022/11/23 14:39
     * @auther YangSuzy
     **/
    @GetMapping("/get-user-home-info")
    public ResultBean<UserHomeVO> getUserHomeInfo(@RequestParam(value = "uid", required = false) String uid,
                                                  @RequestParam(value = "username", required = false) String username) {
        return accountService.getUserHomeInfo(uid, username);
    }

    /**
     * 方法名: getUserCalendarHeatmap
     * 描述: 获取用户最近一年的提交热力图
     *
     * @param uid      用户ID
     * @param username 用户名
     * @return web.suzy.oj.common.result.ResultBean<web.suzy.oj.pojo.vo.UserCalendarHeatmapVO>
     * @date 2022/11/23 16:14
     * @auther YangSuzy
     **/
    @GetMapping("/get-user-calendar-heatmap")
    public ResultBean<UserCalendarHeatmapVO> getUserCalendarHeatmap(
            @RequestParam(value = "uid", required = false) String uid,
            @RequestParam(value = "username", required = false) String username) {
        return accountService.getUserCalendarHeatmap(uid, username);
    }
}
